import unittest
from page.y_web_navigation_page import PageNavigationManager
from tools.y_get_data import get_cookies, get_navigation_add_custom as get_custom_data, \
    get_navigation_add_article as get_article_data
from parameterized import parameterized

url = 'http://192.168.8.222/admin.php'


class TestWebNavigationManagerCustom(unittest.TestCase):
    custom = None

    @classmethod
    def setUpClass(cls):
        cls.custom = PageNavigationManager(url)
        cls.custom.driver.add_cookie(get_cookies())  # 添加cookies
        cls.custom.driver.refresh()  # 刷新界面
        cls.custom.click_web_manager_a()  # 点击网站管理菜单
        cls.custom.click_navigation_manager()  # 点击导航管理子菜单
        cls.custom.to_iframe()  # 进入iframe界面

    @classmethod
    def tearDownClass(cls):
        cls.custom.driver.quit()

    @parameterized.expand(get_custom_data())
    def test_web_navigation_manager_custom(self, data, expect):
        info = self.custom.add_custom_navigation(*data)
        try:
            self.assertEqual(expect, info)
        except AssertionError:
            self.custom.get_image('y')
            self.custom.click_custom_add_error_back()
            raise


class TestWebNavigationManagerArticle(unittest.TestCase):
    article = None

    @classmethod
    def setUpClass(cls):
        cls.article = PageNavigationManager(url)
        cls.article.driver.add_cookie(get_cookies())  # 添加cookies
        cls.article.driver.refresh()  # 刷新界面
        cls.article.click_web_manager_a()  # 点击网站管理菜单
        cls.article.click_navigation_manager()  # 点击导航管理子菜单
        cls.article.to_iframe()  # 进入iframe界面

    @classmethod
    def tearDownClass(cls):
        cls.article.driver.quit()

    @parameterized.expand(get_article_data())
    def test_web_navigation_manager_article(self, data, expect):
        info = self.article.add_article_navigation(*data)
        try:
            self.assertEqual(expect, info)
        except AssertionError:
            self.article.get_image('y')
            self.article.click_article_add_error_back()
            raise


class TestWebNavigationManagerDeleteData(unittest.TestCase):
    delete = None

    @classmethod
    def setUpClass(cls):
        cls.delete = PageNavigationManager(url)  # 发送请求
        cls.delete.driver.add_cookie(get_cookies())  # 添加cookies
        cls.delete.driver.refresh()  # 刷新界面
        cls.delete.click_web_manager_a()  # 点击网站管理菜单
        cls.delete.click_navigation_manager()  # 点击导航管理子菜单
        cls.delete.to_iframe()  # 进入iframe界面

    @classmethod
    def tearDownClass(cls):
        cls.delete.driver.quit()

    @parameterized.expand([
        [
            (4, 5, 6),
            '删除成功'
        ]
    ])
    def test_delete_select_data(self, nums, expect):
        info = self.delete.delete_select(nums)
        try:
            self.assertEqual(expect, info)
        except AssertionError:
            self.delete.get_image('y')
            raise
